<template>
  <div class="container-item-archive">
    <div v-for="(temp, index) in list" :key="index" class="group-archive">
      <div class="group-left">
        <div class="item-title">
          <el-tag size="mini" :type="temp.state | paresState('tagType')" style="margin-right:20px">{{ temp.state | paresState }}</el-tag>
          <a href="https://www.baidu.com" target="_black">{{ temp.title || '未填写标题' }}</a>
        </div>
        <div class="item-date-state">{{ new Date(temp.created_at) | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</div>
        <div class="item-other-info">
          <span class="item-icon el-icon-files">资源 {{ temp.resources.length }}</span>
          <span class="item-icon el-icon-chat-line-square">评论 0</span>
          <span class="item-icon el-icon-headset">播放 0</span>
          <span class="item-icon el-icon-star-off">点赞 0</span>
        </div>
      </div>
      <div class="group-right">
        <el-button size="mini" type="primary" @click="examineHandler(temp.id,index,2)">通过审核</el-button>
        <el-button size="mini" style="margin-left:20px" @click="examineHandler(temp.id, index,3)">拒绝审核</el-button>
      </div>
    </div>
  </div>
</template>

<script>
// api
import { audioArchiveExamine } from '@/api/audio.js';

export default {
  filters: {
    paresState(state) {
      const obj = {
        0: '编辑中',
        1: '审核中',
        2: '已通过',
        3: '未通过'
      };
      return obj[state];
    }
  },
  props: {
    list: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  data() {
    return {
      centerDialogVisible: false
    };
  },
  methods: {
    async examineHandler(id, index, state) {
      const res = await audioArchiveExamine({ id, state });
      if (res.code !== 200) {
        this.$messge.error('操作失败');
        return;
      }
      this.list.splice(index, 1);
      this.$message({
        type: 'success',
        message: '操作成功'
      });
      this.$emit('delete');
    }
  }
};
</script>

<style lang="scss" scoped>
@import '~@/styles/variables.scss';

.container-item-archive {
  .group-archive {
    padding: 20px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #ddd;
    border-radius: 4px;
    .item-title {
      font-size: 18px;
      display: flex;
      align-items: center;
      a {
        transition: color 0.2s;
        &:hover {
          color: $menuActiveText;
        }
      }
    }
    .item-desc {
      font-size: 12px;
      margin-bottom: 10px;
    }
  }
  .item-date-state {
    font-size: 12px;
    color: #99a2aa;
    padding: 20px 0;
  }
  .item-other-info {
    font-size: 12px;
    color: #99a2aa;
    .item-icon {
      margin-right: 20px;
      &::before {
        margin-right: 5px;
      }
    }
  }
}
</style>
